import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"

enum Api {
  ruleList = "/system-service/menu/listPermissionRule",
  ruleSave = "/system-service/menu/savePermissionRule",
  ruleEdit = "/system-service/menu/updatePermissionRule",
  ruleDelete = "/system-service/menu/deletePermissionRule",
  listAllPermissionValue = "/system-service/menu/listAllPermissionValue",
  listPermissionTree = "/iam-service/menu/listPermissionTree",
}

/**
 * 根据查询树信息
 */
export const listPermissionTree = (params) => defHttp.get({ url: Api.listPermissionTree, params })


/**
 * 菜单数据权限列表接口
 * @param params
 */
export const dataRuleList = (params) => defHttp.get({ url: Api.ruleList, params })
/**
 * 保存或者更新数据规则
 * @param params
 */
export const saveOrUpdateRule = (params, isUpdate) => {
  const url = isUpdate ? Api.ruleEdit : Api.ruleSave
  return defHttp.post({ url: url, params })
}

/**
 * 删除数据权限
 */
export const deleteRule = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.ruleDelete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

/**
 * 根据code获取字典数值
 * @param params
 */
export const ajaxGetDictItems = (params) => defHttp.get({ url: `/infra-service/dictItem/listItem/`, params: { ...params, code: params.code } })

/**
 * 查询所有可用权限
 * @returns
 */
export const listAllPermissionValue = () => defHttp.get({ url: Api.listAllPermissionValue })


export const listWorkspaceMenuTree = (params) => defHttp.get({ url: '/iam-service/menu/listWorkspaceMenuTree' , params})


